package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.exception.MallException;
import com.ymk.bo.goods.GoodsBO;
import com.ymk.core.code.cmd.GoodsCmdCode;
import com.ymk.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

@Service
public class GoodsDelCmd extends ACmd {

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        GoodsBO reqData = super.getData(sign, GoodsBO.class);

        GoodsBO delGoodsBO = new GoodsBO();
        delGoodsBO.setId(reqData.getId());
        this.GoodsService.del(delGoodsBO);

        return respSign;
    }

    @Override
    public CmdSign executeStore(HttpServletRequest request, CmdSign sign) throws Exception {
        return super.executeStore(request, sign);
    }
    @Override
    public CmdSign verify(HttpServletRequest request, CmdSign sign) throws Exception {
        GoodsBO reqData = super.getData(sign, GoodsBO.class);
        if (Objects.isNull(reqData.getId())){
            throw new MallException("id为空");
        }

        return null;
    }

    @Override
    public String getCmdCode() {
        return GoodsCmdCode.GOODS_DEL;
    }

    @Autowired
    private IGoodsService GoodsService;
}